﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Globalization;
using System.Web.Security;
using Pr0ject0.Models;

namespace Pr0ject0.ViewModel
{
    public class ApplicationViewModel
    {
        [Key]
        [Required]
        [Display(Name = "Application ID")]
        public int ID { get; set; }

        [Required]
        [Display(Name = "First Name")]
        public string first { get; set; }

        [Required]
        [Display(Name = "Last Name")]
        public string last { get; set; }

        [Display(Name = "Middle Name")]
        public string middle { get; set; }

        [Required]
        [Display(Name = "Address")]
        public string address1 { get; set; }

        [Display(Name = "Address cont.")]
        public string address2 { get; set; }

        [Required]
        [Display(Name = "City")]
        public string city { get; set; }

        [Required]
        [Display(Name = "State")]
        public string state { get; set; }

        [Required]
        [Display(Name = "Zip Code")]
        public int? zip { get; set; }

        [Required]
        [Display(Name = "Phone Number")]
        public long? phone { get; set; }

        public TimeSpan? monStart { get; set; }
        public TimeSpan? monEnd { get; set; }

        public TimeSpan? tueStart { get; set; }
        public TimeSpan? tueEnd { get; set; }

        public TimeSpan? wedStart { get; set; }
        public TimeSpan? wedEnd { get; set; }

        public TimeSpan? thurStart { get; set; }
        public TimeSpan? thurEnd { get; set; }

        public TimeSpan? friStart { get; set; }
        public TimeSpan? friEnd { get; set; }

        public TimeSpan? satStart { get; set; }
        public TimeSpan? satEnd { get; set; }

        public TimeSpan? sunStart { get; set; }
        public TimeSpan? sunEnd { get; set; }

        public bool desiresFullTime { get; set; }

        public string employer1 { get; set; }
        public string jobAddress1 { get; set; }
        public string jobCity1 { get; set; }
        public string jobState1 { get; set; }
        public long? jobPhone1 { get; set; }
        public DateTime? startDate1 { get; set; }
        public DateTime? endDate1 { get; set; }
        public float? startSalary1 { get; set; }
        public float? endSalary1 { get; set; }
        public string supervisor1 { get; set; }
        public string position1 { get; set; }
        public string reason1 { get; set; }
        public string responsibilities1 { get; set; }

        public string employer2 { get; set; }
        public string jobAddress2 { get; set; }
        public string jobCity2 { get; set; }
        public string jobState2 { get; set; }
        public long? jobPhone2 { get; set; }
        public DateTime? startDate2 { get; set; }
        public DateTime? endDate2 { get; set; }
        public float? startSalary2 { get; set; }
        public float? endSalary2 { get; set; }
        public string supervisor2 { get; set; }
        public string position2 { get; set; }
        public string reason2 { get; set; }
        public string responsibilities2 { get; set; }

        public string employer3 { get; set; }
        public string jobAddress3 { get; set; }
        public string jobCity3 { get; set; }
        public string jobState3 { get; set; }
        public long? jobPhone3 { get; set; }
        public DateTime? startDate3 { get; set; }
        public DateTime? endDate3 { get; set; }
        public float? startSalary3 { get; set; }
        public float? endSalary3 { get; set; }
        public string supervisor3 { get; set; }
        public string position3 { get; set; }
        public string reason3 { get; set; }
        public string responsibilities3 { get; set; }

        public string refName1 { get; set; }
        public string refCompany1 { get; set; }
        public string refTitle1 { get; set; }
        public long? refPhone1 { get; set; }

        public string refName2 { get; set; }
        public string refCompany2 { get; set; }
        public string refTitle2 { get; set; }
        public long? refPhone2 { get; set; }

        public string refName3 { get; set; }
        public string refCompany3 { get; set; }
        public string refTitle3 { get; set; }
        public long? refPhone3 { get; set; }

        public string schoolName1 { get; set; }
        public string major1 { get; set; }
        public int? startYear1 { get; set; }
        public int? endYear1 { get; set; }
        public bool isGraduate1 { get; set; }

        public string schoolName2 { get; set; }
        public string major2 { get; set; }
        public int? startYear2 { get; set; }
        public int? endYear2 { get; set; }
        public bool isGraduate2 { get; set; }

        public string schoolName3 { get; set; }
        public string major3 { get; set; }
        public int? startYear3 { get; set; }
        public int? endYear3 { get; set; }
        public bool isGraduate3 { get; set; }

        public List<JobApplicationModel> CreateApplications(int[] jobIds)
        {
            List<JobApplicationModel> ret = new List<JobApplicationModel>();
            AvailableHoursModel hours;
            List< PreviousJobModel> previous;
            List<ReferenceModel> refernces;
            List<EducationModel> education;

            foreach (int id in jobIds)
            {
                JobApplicationModel model = new JobApplicationModel();

                hours = CreateAvailableHoursModels();
                previous = CreatePreviousJobModels();
                refernces = CreateReferenceModels();
                education = CreateEducationModels();

                model.first = this.first;
                model.last = this.last;
                model.middle = this.middle;
                model.address1 = this.address1;
                model.address2 = this.address2;
                model.city = this.city;
                model.state = this.state;
                model.zip = this.zip;
                model.phone = this.phone;
                model.jobID = id;

                model.hours = hours;
                model.previousJobs = previous;
                model.references = refernces;
                model.education = education;

                ret.Add(model);
            }

            return ret;
        }

        private AvailableHoursModel CreateAvailableHoursModels()
        {
            AvailableHoursModel ret = new AvailableHoursModel();

            ret.monStart = this.monStart;
            ret.monEnd = this.monEnd;
            ret.tueStart = this.tueStart;
            ret.tueEnd = this.tueEnd;
            ret.wedStart = this.wedStart;
            ret.wedEnd = this.wedEnd;
            ret.thurStart = this.thurStart;
            ret.thurEnd = this.thurEnd;
            ret.friStart = this.friStart;
            ret.friEnd = this.friEnd;
            ret.satStart = this.satStart;
            ret.satEnd = this.satEnd;
            ret.sunStart = this.sunStart;
            ret.sunEnd = this.sunEnd;

            return ret;
        }

        private List< PreviousJobModel> CreatePreviousJobModels()
        {
            List<PreviousJobModel> ret = new List<PreviousJobModel>();
            PreviousJobModel prev = new PreviousJobModel();

            prev.employer = this.employer1;
            prev.address = this.jobAddress1;
            prev.city = jobCity1;
            prev.state = this.jobState1;
            prev.phone = this.jobPhone1;
            prev.startDate = this.startDate1;
            prev.endDate = this.endDate1;
            prev.startSalary = this.startSalary1;
            prev.endSalary = this.endSalary1;
            prev.supervisor = this.supervisor1;
            prev.position = this.position1;
            prev.reason = this.reason1;
            prev.responsibilities = this.responsibilities1;

            ret.Add(prev);

            prev = new PreviousJobModel();

            prev.employer = this.employer2;
            prev.address = this.jobAddress2;
            prev.city = jobCity2;
            prev.state = this.jobState2;
            prev.phone = this.jobPhone2;
            prev.startDate = this.startDate2;
            prev.endDate = this.endDate2;
            prev.startSalary = this.startSalary2;
            prev.endSalary = this.endSalary2;
            prev.supervisor = this.supervisor2;
            prev.position = this.position2;
            prev.reason = this.reason2;
            prev.responsibilities = this.responsibilities2;

            ret.Add(prev);

            prev = new PreviousJobModel();

            prev.employer = this.employer3;
            prev.address = this.jobAddress3;
            prev.city = jobCity3;
            prev.state = this.jobState3;
            prev.phone = this.jobPhone3;
            prev.startDate = this.startDate3;
            prev.endDate = this.endDate3;
            prev.startSalary = this.startSalary3;
            prev.endSalary = this.endSalary3;
            prev.supervisor = this.supervisor3;
            prev.position = this.position3;
            prev.reason = this.reason3;
            prev.responsibilities = this.responsibilities3;

            ret.Add(prev);

            return ret;
        }

        private List<ReferenceModel> CreateReferenceModels()
        {
            List<ReferenceModel> ret = new List<ReferenceModel>();
            ReferenceModel reference = new ReferenceModel();

            reference.name = this.refName1;
            reference.company = this.refCompany1;
            reference.title = this.refTitle1;
            reference.phone = this.refPhone1;

            ret.Add(reference);

            reference = new ReferenceModel();

            reference.name = this.refName2;
            reference.company = this.refCompany2;
            reference.title = this.refTitle2;
            reference.phone = this.refPhone2;

            ret.Add(reference);

            reference = new ReferenceModel();

            reference.name = this.refName3;
            reference.company = this.refCompany3;
            reference.title = this.refTitle3;
            reference.phone = this.refPhone3;

            ret.Add(reference);

            return ret;
        }

        private List<EducationModel> CreateEducationModels()
        {
            List<EducationModel> ret = new List<EducationModel>();
            EducationModel ed = new EducationModel();

            ed.name = this.schoolName1;
            ed.major = this.major1;
            ed.startYear = this.startYear1;
            ed.endYear = this.endYear1;
            ed.isGraduate = this.isGraduate1;

            ret.Add(ed);

            ed = new EducationModel();

            ed.name = this.schoolName2;
            ed.major = this.major2;
            ed.startYear = this.startYear2;
            ed.endYear = this.endYear2;
            ed.isGraduate = this.isGraduate2;

            ret.Add(ed);

            ed = new EducationModel();

            ed.name = this.schoolName3;
            ed.major = this.major3;
            ed.startYear = this.startYear3;
            ed.endYear = this.endYear3;
            ed.isGraduate = this.isGraduate3;

            ret.Add(ed);

            return ret;
        }
    }
}